﻿using System.Collections.Generic;
using System.Linq;

namespace MedReg
{
    public partial class Retrainment
    {
        public void ImportList(List<Classes.Retrainment> RetrainmentList)
        {
            var mdb = new MedregDBDataContext();

            var sSertSpec = new Classes.SertificateSpeciality();
            var SertSpec = new SertificateSpeciality();
            SertSpec.ImportList(sSertSpec.getSertificateSpecialityList(RetrainmentList));

            var sEdInst = new Classes.EducationInstitution();
            var EdInst = new EducationInstitution();
            EdInst.ImportList(sEdInst.getEducationInstitutionList(RetrainmentList));


            foreach (Classes.Retrainment retrainment in RetrainmentList)
            {
                var retrainment1 = new Retrainment
                                        {
                                            Organisation = retrainment.Organisation.ID,
                                            EducationSpeciality = retrainment.EducationSpeciality.ID,
                                            DiplomaSerie = retrainment.DiplomaSerie,
                                            DiplomaNumber = retrainment.DiplomaNumber,
                                            Hours = retrainment.Hours,
                                            TrainingDate = retrainment.TrainingDate,
                                            Employee = retrainment.Employee.ID
                                        };

                IEnumerable<Retrainment> query = (from cr in mdb.Retrainment
                                                  where cr.Employee == retrainment.Employee.ID
                                                  select cr
                                                   ).ToList();
                mdb.Retrainment.DeleteAllOnSubmit(query);
                mdb.Retrainment.InsertOnSubmit(retrainment1);
            }
            mdb.SubmitChanges();
        }
    }
}